Page({

  /**
   * 页面的初始数据
   */
  data: {
    ifShownoData: true,
    orderStatus: [
      {
        "statusName": "全部",
        "statusCode": ""
      },
      {
        "statusName": "废纸",
        "statusCode": "A01",
      },
      {
        "statusName": "废塑料",
        "statusCode": "A30",
      },
      {
        "statusName": "废钢铁",
        "statusCode": "A10",
      }
      // ,
      // {
      //   "statusName": "废金属",
      //   "statusCode": "A01",
      // }
    ],

    statusSelect: "",//判断是否选中
    result: "",
    statusName: "",
    pageIndex: 1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    var that = this;
    that.onMarketInfo();

  },

  onMarketInfo: function () {
    var that = this;
    var arr = new Array;
    wx.showLoading({
      title: '拼命加载中',
    });
    wx.request({
      method: "POST",
      url: 'https://www.zaishengwang.com/wx/priceList.do',
      dataType: 'json',
      header: {
        'content-type': 'application/x-www-form-urlencoded',
      },
      data: {
        categoryId: that.data.statusName,
        page: that.data.pageIndex,
        size: 20,
        setTop: 1,
      },
      success: function (res) {
        wx.hideLoading();
        if (res.data.quotationtrend.result.length > 0) {
          for (var i = 0; i < res.data.quotationtrend.result.length; i++) {
            let createTime = res.data.quotationtrend.result[i].createTime.substring(0, 19);
            res.data.quotationtrend.result[i].createTime = createTime;
          }
          arr = res.data.quotationtrend.result;
          that.setData({ ifShownoData: true });
        } else {
          that.setData({ ifShownoData: false });
        }

        if (that.data.pageIndex != 1) {
          var array = that.data.result;
          array = array.concat(arr);
          that.setData({ ifShownoData: true, result: array });
        } else {
          that.setData({ result: arr });
        }

      },
      fail: function (error) {
      }
    })

  },

  marketStatusList: function (e) {
    var that = this;
    var statusName = e.currentTarget.dataset.select;
    if (statusName == "全部") {
      statusName = "";
    }
    that.setData({//把选中值放入判断值
      statusSelect: e.currentTarget.dataset.select,
      statusName: statusName,
      result: "",
      pageIndex: 1
    });
    that.onMarketInfo();
  },
  goMarketList: function (e) {
    console.log(e.currentTarget.dataset.id);
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: 'market_list?id=' + id,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
  onPullDownRefresh: function () {
    var that = this;
    that.setData({
      pageIndex: 1, // 每次触发下拉事件pageIndex=1
      result: "",
    });
    that.onMarketInfo();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    that.setData({
      pageIndex: that.data.pageIndex + 1,

    })
    // 上拉获取更多数据
    that.onMarketInfo();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
